package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.DefaultValueEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.PatternEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.DistributorAddressEnum;
import com.xbongbong.saas.enums.DistributorCreditStatusEnum;
import com.xbongbong.saas.enums.DistributorSettlementMethodEnum;
import com.xbongbong.saas.enums.DistributorSourceEnum;
import com.xbongbong.saas.enums.GradeEnum;
import com.xbongbong.saas.enums.PhoneExtEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.DistributorEnum;
import com.xbongbong.saas.enums.dictionary.CustomerScaleEnum;
import com.xbongbong.saas.enums.dictionary.DistributorLevelEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 经销商枚举
 *
 * @author xinpeng.jiang
 * @version 1.0
 * @date 2020/12/21 16:41
 * @since V1.0
 */
@Getter
public enum TempCustomerManagementDistributorEnum {
    // 经销商枚举
    BASE_INFO(DistributorEnum.BASE_INFO),
    NAME(DistributorEnum.NAME),
    NAME_SHORT(DistributorEnum.NAME_SHORT),
    AREA(DistributorEnum.AREA),
    SCALE(DistributorEnum.SCALE),
    PHONE(DistributorEnum.PHONE),
    ADDRESS(DistributorEnum.ADDRESS),
    SHIPPING_ADDRESS(DistributorEnum.SHIPPING_ADDRESS),
    OWNER_ID(DistributorEnum.OWNER_ID),
    COUSERID(DistributorEnum.COUSERID),
    SETTLEMENT_METHOD(DistributorEnum.SETTLEMENT_METHOD),
    PAYMENT_BY_CREDIT(DistributorEnum.PAYMENT_BY_CREDIT),
    ASSOCIATED_INFO(DistributorEnum.ASSOCIATED_INFO),
    ADD_CONTACT(DistributorEnum.ADD_CONTACT),
    EXTEND_INFO(DistributorEnum.EXTEND_INFO),
    SOURCE(DistributorEnum.SOURCE),
    CREDIT(DistributorEnum.CREDIT),
    FINANCIAL_SITUATION(DistributorEnum.FINANCIAL_SITUATION),
    MARKETABILITY(DistributorEnum.MARKETABILITY),
    OPERATING_CONDITIONS(DistributorEnum.OPERATING_CONDITIONS),
    MANAGEMENT_ABILITY(DistributorEnum.MANAGEMENT_ABILITY),
    BUSINESS_SCALE(DistributorEnum.BUSINESS_SCALE),
    PURCHASEABLE_GOODS(DistributorEnum.PURCHASEABLE_GOODS),
    SYSTEM_INFO(DistributorEnum.SYSTEM_INFO),
    ADD_TIME(DistributorEnum.ADD_TIME),
    UPDATE_TIME(DistributorEnum.UPDATE_TIME),
    LAST_CONNECT_TIME(DistributorEnum.LAST_CONNECT_TIME),
    // DISTRIBUTION_DATE(DistributorEnum.DISTRIBUTION_DATE),
    CREATOR_ID(DistributorEnum.CREATOR_ID),
    BIRTHDAY_FLAG(DistributorEnum.BIRTHDAY_FLAG),
    BIRTHDAY_MMDD(DistributorEnum.BIRTHDAY_MMDD),
    IS_PUBLIC(DistributorEnum.IS_PUBLIC),
    IS_ARCHIVED(DistributorEnum.IS_ARCHIVED),
    DD_CUSTOMER_ID(DistributorEnum.DD_CUSTOMER_ID),
    PARENT_HIDE(DistributorEnum.PARENT_HIDE),
    CLUE_COMPANY_ID(DistributorEnum.CLUE_COMPANY_ID),
    RECEIVABLE_PERIOD(DistributorEnum.RECEIVABLE_PERIOD),
    ;

    private DistributorEnum anEnum;

    TempCustomerManagementDistributorEnum(DistributorEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempCustomerManagementDistributorEnum> getAllEnum() {
        List<TempCustomerManagementDistributorEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initName(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(NAME.getAnEnum().getAttr());
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initScale(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(DistributorLevelEnum.class, fieldAttrEntity.getFieldType()));
        fieldAttrEntity.setDictionaryFlag(1);
    }

    public static void initPhone(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity type = InitExplainsHelper.setField("text_1", "类型", "type", FieldTypeEnum.COMBO.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(PhoneExtEnum.class, FieldTypeEnum.COMBO.getType());
        itemPoJoList.get(0).setChecked(true);
        type.setItems(itemPoJoList);
        type.setRequired(1);
        type.setDictionaryFlag(1);
        type.setParentAttr(PHONE.anEnum.getAttr());
        items.add(type);
        FieldAttrEntity phone = InitExplainsHelper.setField("text_2", "电话", "phone", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        phone.setNoRepeat(1);
        phone.setParentAttr(PHONE.anEnum.getAttr());
        phone.setRequired(1);
        items.add(phone);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setDictionaryFlag(1);
    }

    public static void initAddress(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("");
        fieldAttrEntity.setShowDetailAddress(1);
    }

    public static void initShippingAddress(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity receiver = InitExplainsHelper.setField(DistributorAddressEnum.RECEIVER.getAttr(), DistributorAddressEnum.RECEIVER.getName(), DistributorAddressEnum.RECEIVER.getSaasAttr(), FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        receiver.setParentAttr(SHIPPING_ADDRESS.anEnum.getAttr());
        receiver.setRequired(1);
        items.add(receiver);
        FieldAttrEntity phone = InitExplainsHelper.setField(DistributorAddressEnum.PHONE.getAttr(), DistributorAddressEnum.PHONE.getName(), DistributorAddressEnum.PHONE.getSaasAttr(), FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        phone.setParentAttr(SHIPPING_ADDRESS.anEnum.getAttr());
        phone.setRequired(1);
        items.add(phone);
        FieldAttrEntity postcode = InitExplainsHelper.setField(DistributorAddressEnum.POSTCODE.getAttr(), DistributorAddressEnum.POSTCODE.getName(), DistributorAddressEnum.POSTCODE.getSaasAttr(), FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        postcode.setPatternType(PatternEnum.POSTCODE.getType());
        postcode.setParentAttr(SHIPPING_ADDRESS.anEnum.getAttr());
        postcode.setRequired(1);
        postcode.setVerifyMessage("邮政编码错误，请重新输入");
        postcode.setVerifyRule("^[0-9][0-9]{5}$");
        items.add(postcode);
        FieldAttrEntity address = InitExplainsHelper.setField(DistributorAddressEnum.ADDRESS.getAttr(), DistributorAddressEnum.ADDRESS.getName(), DistributorAddressEnum.ADDRESS.getSaasAttr(), FieldTypeEnum.ADDRESS.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        address.setParentAttr(SHIPPING_ADDRESS.anEnum.getAttr());
        address.setRequired(1);
        items.add(address);
        FieldAttrEntity setDefault = InitExplainsHelper.setField(DistributorAddressEnum.SET_DEFAULT.getAttr(), DistributorAddressEnum.SET_DEFAULT.getName(), DistributorAddressEnum.SET_DEFAULT.getSaasAttr(), FieldTypeEnum.SWITCH.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        setDefault.setParentAttr(SHIPPING_ADDRESS.anEnum.getAttr());
        items.add(setDefault);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
    }

    public static void initCoUserId(FieldAttrEntity fieldAttrEntity) {
        //可新增权限：超级管理员、老板、销售主管、创建人、负责人、负责人主管
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setSetType(3);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setRequired(0);
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setShowEditable(0);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setSetType(3);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.DYNAMIC.getAlias());
        defaultAttrPoJo.setDefaultValue(DefaultValueEnum.LOGIN_USER.getValue());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

    public static void initSettlementMethod(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(DistributorSettlementMethodEnum.class, FieldTypeEnum.CHECKBOX_GROUP.getType());
        fieldAttrEntity.setItems(itemPoJoList);
        fieldAttrEntity.setRequired(1);
    }

    public static void initPaymentByCredit(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(DistributorCreditStatusEnum.class, FieldTypeEnum.RADIO_GROUP.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }

    public static void initAddContact(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.CONTACT.getCode());
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
    }

    public static void initSource(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(DistributorSourceEnum.class, FieldTypeEnum.COMBO.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }

    public static void initCredit(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(GradeEnum.class, FieldTypeEnum.COMBO.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }

    public static void initMarketability(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(GradeEnum.class, FieldTypeEnum.COMBO.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }

    public static void initFinancialSituation(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(GradeEnum.class, FieldTypeEnum.COMBO.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }

    public static void initOperatingConditions(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(GradeEnum.class, FieldTypeEnum.COMBO.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }

    public static void initManagementAbility(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(GradeEnum.class, FieldTypeEnum.COMBO.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }

    public static void initBusinessScale(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(CustomerScaleEnum.class, FieldTypeEnum.COMBO.getType());
        fieldAttrEntity.setItems(itemPoJoList);
    }


    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initLastConnectTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setRecentTime(true);
        fieldAttrEntity.setDateType(DateTimeEnum.DATETIME.getType());
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    /**
     * 初始化应收账期
     */
    public static void initReceivablePeriod(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsOpen(0);
        fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
        fieldAttrEntity.setNoRepeat(0);
        fieldAttrEntity.setMemo(I18nMessageUtil.getMessage(I18nStringConstant.RECEIVABLE_PERIOD));
    }
}
